package com.ray.controller;

import java.text.ParseException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ray.exception.ServiceException;
import com.ray.pojo.MyUser;
import com.ray.service.ApplyRepairFormService;
import com.ray.service.EnergyService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;
import com.ray.util.ReturnStringUtil;

/**
 * 申补单controller
 * @author nate
 */
@Controller
@RequestMapping("/applyRepairForm")
public class ApplyRepairFormController {
	@Autowired
	ApplyRepairFormService applyRepairFormService;
	
	/**
	 * 获取订单明细
	 * @param orderId(订单编号)
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping("/getOrderInfoDetail")
	@ResponseBody
	public Map getOrderInfoDetail(HttpServletRequest request) throws ServiceException {
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(applyRepairFormService.getOrderInfoDetail(map));
	}
	
	
	/**
	 * 获取登录人车间的用户
	 * @param orderId(订单编号)
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping("/getWorkShopUser")
	@ResponseBody
	public Map getWorkShopUser(HttpServletRequest request) throws ServiceException {
		MyUser myUser=RequestUtil.getLoginUser(request);
		return ResponseUtil.ResponseResult(applyRepairFormService.getWorkShopUser(myUser));
	}
	
	
	
	/**
	 * 获取申补单信息
	 * @param orderId(订单信息 可能是 系统订单编号，工厂型号，客户型号，公司订单编号等)
	 * @param materialDetail(物料信息 可能是 物料名称，规格型号，色号，供应商)
	 * @param status(状态  0未审核 1已审核 2已退回)
	 * @return 
	 * @throws ServiceException
	 */
	@RequestMapping("/getApplyRepairForm")
	@ResponseBody
	public Map getApplyRepairForm(HttpServletRequest request) throws ServiceException {
		Map map=RequestUtil.getRequestAllParam(request);
		return ResponseUtil.ResponseResult(applyRepairFormService.getApplyRepairForm(map));
	}
	
	
	/**
	 * 创建申补单
	 * @param applyArray(申补数组)
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping("/createApplyRepairForm")
	@ResponseBody
	public Map createApplyRepairForm(HttpServletRequest request) throws ServiceException {
		Map  map=RequestUtil.getRequestAllParam(request);
		MyUser myUser=RequestUtil.getLoginUser(request);
		applyRepairFormService.createApplyRepairForm(map,myUser);
		return ResponseUtil.ResponseResult(ReturnStringUtil.CREATE_SUCCESS);
	}
	
	
	/**
	 * 删除申补单
	 * @param id(申补单id)
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping("/deleteApplyRepairForm")
	@ResponseBody
	public Map deleteApplyRepairForm(HttpServletRequest request) throws ServiceException {
		Map map=RequestUtil.getRequestAllParam(request);
		applyRepairFormService.deleteApplyRepairForm(map);
		return ResponseUtil.ResponseResult(ReturnStringUtil.DELETE_SUCCESS);
	}
	
	
	/**
	 * 修改申补单
	 * @param id(申补单id)
	 * @param applyCount(修改数量)
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping("/updateApplyRepairForm")
	@ResponseBody
	public Map updateApplyRepairForm(HttpServletRequest request) throws ServiceException {
		Map map=RequestUtil.getRequestAllParam(request);
		applyRepairFormService.updateApplyRepairForm(map);
		return ResponseUtil.ResponseResult(ReturnStringUtil.UPDATE_SUCCESS);
	}
	
	
	/**
	 * 审核退回
	 * @param id(申补单id)
	 * @param status(状态)
	 * @param conpanyShare(公司占比)
	 * @return
	 * @throws ServiceException
	 */
	@RequestMapping("/approvalApplyRepairForm")
	@ResponseBody
	public Map approvalApplyRepairForm(HttpServletRequest request,int status) throws ServiceException {
		Map map=RequestUtil.getRequestAllParam(request);
		applyRepairFormService.approvalApplyRepairForm(map,status);
		return ResponseUtil.ResponseResult(status==1?ReturnStringUtil.APPROVAL_SUCCESS:ReturnStringUtil.RETURN_SUCCESS);
	}
	
	
	
}
